package com.anolesoft.amljmes.fortysix.service.mapper;

import cn.hutool.core.util.StrUtil;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;

import com.anolesoft.amljmes.fortysix.controller.MesBzzPtmlController;
import com.anolesoft.amljmes.fortysix.dto.MesBzzPtmlDto;

import java.util.List;

@Mapper
public interface MesBzzPtmlServiceMapper {
    // 查询列表
    @SelectProvider(type=createSQL.class, method = "queryMesBzzPtmlSQL")
    List<MesBzzPtmlDto> queryMesBzzPtmlSQL(MesBzzPtmlController.DemoVO demoVO);
    public static class createSQL {
        public static String queryMesBzzPtmlSQL(MesBzzPtmlController.DemoVO demoVO){
            return new SQL(){
                {
                    StringBuilder sql = new StringBuilder();
                    sql.append(" a.objuid as key,a.*,0 as pageNo,10 as pageSize from mes_bzz_ptml a where a.shanchubiaoji=0 ");
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getJixing())){
                        String jixing = demoVO.getJixing();
                        sql.append(" and upper(a.jixing) = trim(upper(#{jixing, jdbcType=VARCHAR}))");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getTuhao())){
                        String tuhao = demoVO.getTuhao();
                        sql.append(" and upper(a.tuhao) = trim(upper(#{tuhao, jdbcType=VARCHAR}))");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getWuliaohao())){
                        String wuliaohao = demoVO.getWuliaohao();
                        sql.append(" and upper(a.wuliaohao) = trim(upper(#{wuliaohao, jdbcType=VARCHAR}))");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getZhuanye())){
                        String zhuanye = demoVO.getZhuanye();
                        sql.append(" and upper(a.zhuanye) = trim(upper(#{zhuanye, jdbcType=VARCHAR}))");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getChengzhidanwei())){
                        String chengzhidanwei = demoVO.getChengzhidanwei();
                        sql.append(" and upper(a.chengzhidanwei) = trim(upper(#{chengzhidanwei, jdbcType=VARCHAR}))");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getYijiaodanwei())){
                        String yijiaodanwei = demoVO.getYijiaodanwei();
                        sql.append(" and upper(a.yijiaodanwei) = trim(upper(#{yijiaodanwei, jdbcType=VARCHAR}))");
                    }
                    if(!StrUtil.isEmptyOrUndefined(demoVO.getChangdaihao())){
                        String changdaihao = demoVO.getChangdaihao();
                        sql.append(" and upper(a.changdaihao) = upper(#{changdaihao, jdbcType=VARCHAR})");
                    }
                    SELECT(sql.toString());
                }
            }.toString();
        }
    }
}
